package control

import (
	"gin.study/middleware"
	"github.com/gin-gonic/gin"
	"github.com/gin-gonic/gin/testdata/protoexample"
	"net/http"
)

func Routers(c *gin.Engine) {
	c.GET("/", middleware.BeforeHandlers, HelloHandler)  //单个路由局部使用中间件
	c.GET("/p", GetUrlQueryHandler)
	c.GET("/p/:id/:name/", GetUrlParamHandler)
	c.POST("/pform", GetFormParamHandler)
	c.POST("/file", UploadFileHandler)
	c.POST("/files", MultiFileHandler)
	c.GET("/get", middleware.AuthMiddleWare(),DoGet)
	c.GET("submit", Submit)
	c.POST("/json", ParseJson)
	c.POST("/form", ParseForm)
	c.POST("/parse", SomeHandler)
	//protobuf格式解析
	c.GET("/someProtoBuf", func(c *gin.Context) {
		reps := []int64{int64(1), int64(2)}
		label := "test"
		// The specific definition of protobuf is written in the testdata/protoexample file.
		data := &protoexample.Test{
			Label: &label,
			Reps:  reps,
		}
		// Note that data becomes binary data in the response
		// Will output protoexample.Test protobuf serialized data
		c.ProtoBuf(http.StatusOK, data)
	})
	//使用JSONP从不同域中的服务器请求数据。如果查询参数回调存在，则向响应体添加回调。
	c.GET("/jsonp", func(c *gin.Context) {
		data := gin.H{
			"foo": "bar",
		}

		//callback is x
		// Will output  :   x({\"foo\":\"bar\"})
		c.JSONP(http.StatusOK, data)
	})
	//使用AsciiJSON生成带有转义非ascii字符的纯AsciiJSON。
	c.GET("/someJSON", func(c *gin.Context) {
		data := gin.H{
			"lang": "GO语言",
			"tag":  "<br>",
		}

		// will output : {"lang":"GO\u8bed\u8a00","tag":"\u003cbr\u003e"}
		c.AsciiJSON(http.StatusOK, data)
	})

	c.GET("/index",RenderTemp)
	c.GET("/user",RenderUser)
	c.GET("/header",RenderHeader)
	c.GET("/redirect", Redirect)

	c.GET("/cookie",DoCookie)
}


